#include "Dust.h"
#include <GL/gl.h>

DustPan::DustPan(vec2i s, Flob* mf) : myFlob(mf), field(NULL){
	resize(s);
}
DustPan::~DustPan(){
	for(size_t i=0; i<size; ++i)
		delete field[i];
	delete [] field;
}
void DustPan::resize(vec2i s){
	if(field){
		Particle** nb = new Particle*[s.x*s.y];
		for(size_t i=0; i<s.x*s.y; ++i)
			nb[i]=NULL;
		for(int y=0; y<sizexy.y; ++y){
			for(int x=0; x<sizexy.x; ++x){
				if(y<s.y && x<s.x){
					nb[s.x*y+s.x]=field[sizexy.x*y+x];
				}
				else{
					delete field[sizexy.x*y+x];
				}
			}
		}
		delete [] field;
		field=nb;
		sizexy=s;
		size=s.x*s.y;
	}
	else{
		sizexy=s;
		size=s.x*s.y;
		field = new Particle*[size];
		for(size_t i=0; i<size; ++i)
			field[i]=NULL;
	}
}
void DustPan::step(float dt){

}
void DustPan::draw(){
	glColor4f(1.f,1.f,1.f,1.f);
	glPointSize(1.f);
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_POINTS);
	size_t i=0;
	for(int y=0; y<sizexy.y; ++y){
		for(int x=0; x<sizexy.x; ++x){
			if(field[i])
				glVertex2i(x,y);
			++i;
		}
	}
	glEnd();
}














